package com.etongwl.socketlibrary.library2;

/**
 * Created by jason on 16/6/27.
 * 发送的消息
 */
public class MessageCore {
    int  what;//消息
    String msg;
    Object obj;

    HanderCore target;

    public int getWhat() {
        return what;
    }

    public void setWhat(int what) {
        this.what = what;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getObj() {
        return obj;
    }

    public void setObj(Object obj) {
        this.obj = obj;
    }


    public static synchronized MessageCore obtain(HanderCore h) {
        MessageCore m = new MessageCore();
        m.target = h;
        return m;
    }
    public void sendToTarget() {//发送消息
//        System.out.println("add message to Message Queue");
        synchronized (this){
            target.sendMessage(this);
        }
    }



    public void recycle(){
        this.msg =null;
        this.msg =null;
        this.what =0;
        this.target =null;
    }

    @Override
    public String toString() {
        return "MessageCore{" +
                "what=" + what +
                ", msg='" + msg + '\'' +
                ", obj=" + obj +
                '}';
    }
}
